package com.etc.test1;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestMain1 {

    public static void main(String[] args) {
        
        // 创建对象， 设置属性
        BookType bt = new BookType();
        bt.setName("java");
        // 创建对象，设置属性
        Book book = new Book();
        book.setAuthor("tom");
        book.setName("thinking in java");
        book.setBtype(bt);
        
        System.out.println(book);
        System.out.println("====================");
        // IOC: 是通过spring context 容器管理
        // 实例化容器
        ApplicationContext context = new ClassPathXmlApplicationContext("application-Context.xml");
        // 从容器中根据  类型 获取对象
//        BookType bt1 = context.getBean(BookType.class); // 容器中有2个类型
//        System.out.println(bt1);
        // 根据容器中的id 获取对象
        Object bt2 = context.getBean("bt");
        System.out.println(bt2);
        // Spring容器是单例的 scope="prototype" 每次取的时候新建一个对象
//        System.out.println(bt1 == bt2);
        
        
        System.out.println("=================");
        
        Book bk = context.getBean(Book.class);
        System.out.println(bk);
        
        System.out.println("=======================");
        BookType bt3 = context.getBean("bt1", BookType.class);
        System.out.println(bt3);
    }
}
